home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1998 August / macformat-066.iso / How-to's / Foreign Files / Creator Changer 2.8.4 / Code & Resource / Creator Changer.menu.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-07-18  |  5.6 KB  |  179 lines  |  [TEXT/KAHL]

  1. /**********************************************************************
  2.  *    This file handles all of the pop-up menu options.  It updates the
  3.  *    menu when needed, and decides what parts were clicked on.
  4.  **********************************************************************/
  5.  
  6. #include    "Creator Changer.h"
  7. #include    "Creator Changer.menu.h"
  8.  
  9.  
  10. /**********************************************************************
  11.  *    Function Handle_pop_up_menu(), this function handles the events
  12.  *    given to the prefered types pop-up menu.
  13.  **********************************************************************/
  14.  
  15. void Handle_Pt_Pop_Up(DialogRef the_dialog, short menu_id, short creator, short file, short description)
  16.     {
  17.     
  18.     Handle        creator_handle, file_handle, desc_handle, menu_handle;
  19.     short        item_type, the_choice, the_item;
  20.     Rect        creator_rect, file_rect, the_rect;
  21.     pref_types    rsrc_handle;
  22.     Str32        description_type;
  23.     Str4        creator_type, file_type;
  24.     
  25.     GetDialogItem(the_dialog, menu_id, &the_item, &menu_handle, &the_rect);
  26.     
  27.     the_choice=GetControlValue((ControlHandle)menu_handle);
  28.     if(the_choice)
  29.         {
  30.         UseResFile(CreatorChangerPref);
  31.             rsrc_handle=**(pref_types **)GetResource(PREF_PT, The_pt_Type[the_choice]);
  32.             if(description) p_Str_Copy(rsrc_handle.Description, description_type);
  33.             p_Str_Copy(rsrc_handle.CreatorType, creator_type);
  34.             p_Str_Copy(rsrc_handle.FileType, file_type);
  35.             ReleaseResource((Handle)&rsrc_handle);
  36.         UseResFile(CreatorChangerApp);
  37.         
  38.         if(description)
  39.             {
  40.             GetDialogItem(the_dialog, description, &item_type, &desc_handle, &file_rect);
  41.             SetDialogItemText(desc_handle, description_type);
  42.             }
  43.         
  44.         GetDialogItem(the_dialog, creator, &item_type, &creator_handle, &creator_rect);
  45.         SetDialogItemText(creator_handle, creator_type);
  46.     
  47.         GetDialogItem(the_dialog, file, &item_type, &file_handle, &file_rect);
  48.         SetDialogItemText(file_handle, file_type);
  49.         }
  50.     (**(ControlHandle)menu_handle).contrlValue=0;
  51.     if(!description) Draw1Control((ControlHandle)menu_handle);
  52.     PT_Item_To_Edit=the_choice;
  53.         
  54.     }
  55.  
  56.  
  57.  
  58. /**********************************************************************
  59.  *    Function Make_Pop_Up_Menu(), this function makes the pop-up menu
  60.  *    for the prefered types menu.
  61.  **********************************************************************/
  62.  
  63. void Make_Pop_Up_Menu(short ID, OSType the_type, short num)
  64.     {
  65.     
  66.     short        item;
  67.     MenuHandle    menu_handle;
  68.     pref_types    **rsrc_handle_pt;
  69.     auto_chng    **rsrc_handle_ac;
  70.     
  71.     menu_handle=GetMenu(ID);
  72.     DisposeMenu(menu_handle);
  73.     
  74.     menu_handle=GetMenu(ID);
  75.     UseResFile(CreatorChangerPref);
  76.         for(item=0;item<num;item++)
  77.             {
  78.             if(the_type==PREF_PT)
  79.                 {
  80.                 The_pt_Type[item+1]=item+Strt_Rsrc;
  81.                 rsrc_handle_pt=(pref_types **)GetResource(the_type, item+Strt_Rsrc);
  82.                 HLock((Handle)rsrc_handle_pt);
  83.                 InsertMenuItem(menu_handle, (**rsrc_handle_pt).Description, item+1);
  84.                 HUnlock((Handle)rsrc_handle_pt);
  85.                 ReleaseResource((Handle)rsrc_handle_pt);
  86.                 }
  87.             else if(the_type==PREF_AC)
  88.                 {
  89.                 The_ac_Type[item+1]=item+Strt_Rsrc;
  90.                 rsrc_handle_ac=(auto_chng **)GetResource(PREF_AC, item+Strt_Rsrc);
  91.                 HLock((Handle)rsrc_handle_ac);
  92.                 InsertMenuItem(menu_handle, (**rsrc_handle_ac).Name, item+1);
  93.                 HUnlock((Handle)rsrc_handle_ac);
  94.                 ReleaseResource((Handle)rsrc_handle_ac);
  95.                 }
  96.             }
  97.     UseResFile(CreatorChangerApp);
  98.     
  99.     }
  100.  
  101.  
  102.  
  103. /**********************************************************************
  104.  *    Function Handle_Ac_Pop_Up(), this function handles the events
  105.  *    given to the auto change pop-up menu.
  106.  **********************************************************************/
  107.  
  108. void Handle_Ac_Pop_Up(DialogRef the_dialog, short menu_id, short from_file_id, short to_creator_id, short to_file_id)
  109.     {
  110.     
  111.     Handle        the_handle, menu_handle;
  112.     short        the_type, the_choice, the_item;
  113.     Rect        the_rect;
  114.     auto_chng    rsrc_handle;
  115.     Str16        name;
  116.     Str4        from_file, to_creator, to_file;
  117.     
  118.     GetDialogItem(the_dialog, menu_id, &the_item, &menu_handle, &the_rect);
  119.     
  120.     the_choice=GetControlValue((ControlHandle)menu_handle);
  121.     if(the_choice)
  122.         {
  123.         UseResFile(CreatorChangerPref);
  124.             rsrc_handle=**(auto_chng **)GetResource(PREF_AC, The_ac_Type[the_choice]);
  125.             p_Str_Copy(rsrc_handle.FromFile,  from_file);
  126.             p_Str_Copy(rsrc_handle.ToCreator, to_creator);
  127.             p_Str_Copy(rsrc_handle.ToFile,       to_file);
  128.             ReleaseResource((Handle)&rsrc_handle);
  129.         UseResFile(CreatorChangerApp);
  130.         
  131.         GetDialogItem(the_dialog, from_file_id, &the_type, &the_handle, &the_rect);
  132.         SetDialogItemText(the_handle, from_file);
  133.         
  134.         GetDialogItem(the_dialog, to_creator_id, &the_type, &the_handle, &the_rect);
  135.         SetDialogItemText(the_handle, to_creator);
  136.     
  137.         GetDialogItem(the_dialog, to_file_id, &the_type, &the_handle, &the_rect);
  138.         SetDialogItemText(the_handle, to_file);
  139.         }
  140.     (**(ControlHandle)menu_handle).contrlValue=0;
  141.     Draw1Control((ControlHandle)menu_handle);
  142.     AC_Item_To_Edit=the_choice;
  143.         
  144.     }
  145.  
  146.  
  147.  
  148. /**********************************************************************
  149.  *    Function Maintain_Menu_Items(), this function 
  150.  **********************************************************************/
  151.     
  152. void Maintain_Menu_Items(WindowRef the_dialog)
  153.     {
  154.     
  155.     if(the_dialog!=NIL_PTR)
  156.         {
  157.         if(the_dialog==Chng.dialog || the_dialog==Edit.dialog || the_dialog== Auto.dialog || the_dialog==Pref.dialog)
  158.             {
  159.             EnableItem(Apple_Menu, ENTIRE_MENU);
  160.             DisableItem(File_Menu, ENTIRE_MENU);
  161.             EnableItem(Edit_Menu, ENTIRE_MENU);
  162.             }
  163.         else if(the_dialog==About.dialog)
  164.             {
  165.             DisableItem(Apple_Menu, ENTIRE_MENU);
  166.             DisableItem(Edit_Menu, ENTIRE_MENU);
  167.             DisableItem(File_Menu, ENTIRE_MENU);
  168.             }
  169.         }
  170.     else if(the_dialog==NIL_PTR)
  171.         {
  172.         EnableItem(Apple_Menu, ENTIRE_MENU);
  173.         EnableItem(File_Menu, ENTIRE_MENU);
  174.         DisableItem(Edit_Menu, ENTIRE_MENU);
  175.         }
  176.  
  177.     DrawMenuBar();
  178.     
  179.     }